nition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    vector<vector<int>> levelOrderBottom(TreeNode* root) {
                vector<vector<int>> vv;

        if(root==nullptr)
        return vv;
        
        queue<TreeNode*> q;
        //用一个 levelSize 记录每层的数据个数
        int levelSize=1;
        q.push(root);
        vector<int> vlevel;
        while(!q.empty())
        {
            while(levelSize--)
            {
                TreeNode* head=q.front();
                q.pop();
                if(head->left!=nullptr)
                {
                    q.push(head->left);
                }
                if(head->right!=nullptr)
                {
                    q.push(head->right);
                }
                vlevel.push_back(head->val);
            }
            levelSize=q.size();
            vv.push_back(vlevel);
            vlevel.clear();
        }
    reverse(vv.begin(),vv.end());
    return vv;
    }
};
